package leetcode;

import javax.swing.tree.TreeNode;

public class Solution19 {
    TreeNode max;
    public boolean isValidBST(TreeNode root) {
        if(root == null){
            return true;
        }

        //左中右
        boolean left = isValidBST(root.left);
        if(!left){
            return false;
        }

        if(max != null && max.val >= root.val){
            return false;
        }
        max = root;

        boolean right = isValidBST(root.right);
        return right;
    }
}
